﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Kooboo.CMS.SiteConverter;
using Kooboo.CMS.SiteConverter.Parser;

namespace Kooboo.CMS.SiteConverter.Winform
{
    class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void Main1(string[] args)
        {
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var testDirectory = Path.Combine(baseDirectory.Substring(0, baseDirectory.Length - "bin\\Debug\\".Length), "test\\");

            var inputStream = new MemoryStream();
            var inputZip = new Ionic.Zip.ZipFile(Encoding.UTF8);
            inputZip.AddFiles(Directory.GetFiles(testDirectory, "*", SearchOption.AllDirectories));
            inputZip.Save(inputStream);

            Console.WriteLine("Please enter the output directory,");
            Console.WriteLine("(Press enter key to output to the desktop by default):");
            var outputZip = Console.ReadLine();
            Console.WriteLine("Parsing...");
            Console.WriteLine();
            if (string.IsNullOrEmpty(outputZip))
                outputZip = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            outputZip = Path.Combine(outputZip, "OutputSite.zip");

            var outputStream = new MemoryStream();
            ParserUtility.ParseZip(inputStream, outputStream, Encoding.UTF8, ParserType.Razor);
            File.WriteAllBytes(outputZip, outputStream.ToArray());

            Console.WriteLine("Great! Site package has been exported to:");
            Console.WriteLine(outputZip);
            Console.ReadLine();
        }
    }
}
